"""
http://ihrm-test.itheima.net/api/company/department/:id
"""
import requests
from common.get_id import get_department_id
from common.get_token import get_login_token

token = get_login_token()
department_id = get_department_id()

resp = requests.post(url="http://ihrm-test.itheima.net/api/company/department",
                     headers={"Authorization": token},
                     json={"name": "Test部门", "code": "66778899"})
print("部门添加", resp.json())


resp = requests.put(url="http://ihrm-test.itheima.net/api/company/department/" + department_id,
                    headers={"Authorization": token},
                    json={"name": "测试部门", "code": "66778899"})
print("部门修改", resp.json())

resp = requests.get(url="http://ihrm-test.itheima.net/api/company/department/" + department_id,
                    headers={"Authorization": token})
print("获取部门信息", resp.json())

# 部门的删除, 删除之后, 就无法再通过部门ID, 查询到部门信息(这个接口, 是真删除了数据.)
# 部门接口的部门ID, 删除之后, 就无法在调用修改\查询\删除. 可以动态获取添加之后的部门ID
resp = requests.delete(url="http://ihrm-test.itheima.net/api/company/department/" + department_id,
                       headers={"Authorization": token})
print("删除部门", resp.json())
